/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sales.managedbean;

import javax.faces.event.ActionEvent;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import sales.entity.LineItem;
import sales.entity.SalesInquiry;

/**
 *
 * @author frankxgz
 */
@ManagedBean
@ViewScoped
public class CreateInquiryResultManagedBean implements Serializable {

    private SalesInquiry inquiry;
    private List<LineItem> lineItems;
    private Long inquiryId;
    private String message;

    /** Creates a new instance of CreateInquiryResultManagedBean */
    public CreateInquiryResultManagedBean() {
    }

    public void initView(PhaseEvent event) {

        if (inquiry == null) {

            inquiry = (SalesInquiry) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("newInquiry");
        }

        setLineItems(inquiry.getInquiryLineItems());
        setInquiryId(inquiry.getId());
        message = "Sales Inquiry has been saved. ID: " + String.valueOf(inquiryId);

    }

    public void editInquiry() throws IOException {
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("inquiry", inquiry);
        FacesContext.getCurrentInstance().getExternalContext().redirect("editSalesInquiry.xhtml");
    }

    public void goBack() throws IOException {
        FacesContext.getCurrentInstance().getExternalContext().redirect("./salesInquiry.xhtml");
    }

    public void goBack2() throws IOException {
        FacesContext.getCurrentInstance().getExternalContext().redirect("./deleteSalesInquiry.xhtml");
    }

    public SalesInquiry getInquiry() {
        return inquiry;
    }

    public void setInquiry(SalesInquiry inquiry) {
        this.inquiry = inquiry;
    }

    public List<LineItem> getLineItems() {
        return lineItems;
    }

    public void setLineItems(List<LineItem> lineItems) {
        this.lineItems = lineItems;
    }

    public Long getInquiryId() {
        return inquiryId;
    }

    public void setInquiryId(Long inquiryId) {
        this.inquiryId = inquiryId;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
